package com.restaurant.application.indexes.reservationlist.mysql;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.nebutown.base.Unit;
import com.nebutown.description.data.SortSpec;
import com.nebutown.generation.basictype.UID;
import com.nebutown.supporthome.AbstractIndex;

import java.sql.ResultSet;
import java.util.List;
import java.util.Map;

public class ReservationListImpl extends AbstractIndex<ReservationListCriteria, ReservationListBean> {

    @Override
    public String getTableName() {
        return "" + getConnectionName() + ".RESERVATIONLIST";
    }

    @Override
    public ReservationListBean newBean() {
        return new ReservationListBean();
    }

    @Override
    public ReservationListCriteria newCriteria() {
        return new ReservationListCriteria();
    }

    @Override
    public List<String> getFieldNames() {
        return Lists.newArrayList(
                "reservationUid",
                "id",
                "createTime",
                "modifyTime",
                "number",
                "shopUid",
                "shopName",
                "serviceName",
                "personAmount",
                "date",
                "time",
                "customerId",
                "customerUid",
                "customerName",
                "phone",
                "remarks",
                "state");
    }

    @Override
    public List<String> getDateFields() {
        return Lists.newArrayList(
                "createTime",
                "modifyTime",
                "date");
    }

    @Override
    public List<String> getDoubleFields() {
        return Lists.newArrayList(
                "");
    }

    @Override
    public Map<String, String> getFieldLabels() {
        return ImmutableMap.<String, String>builder()
                .put("id", "预约id")
                .put("createTime", "创建时间")
                .put("modifyTime", "修改时间")
                .put("number", "预约编号")
                .put("shopUid", "门店Uid")
                .put("shopName", "门店名称")
                .put("serviceName", "服务名称")
                .put("personAmount", "预约人数")
                .put("date", "预约日期")
                .put("time", "时间段")
                .put("customerId", "客户Id")
                .put("customerUid", "客户Uid")
                .put("customerName", "客户名称")
                .put("phone", "预约人联系方式")
                .put("remarks", "备注")
                .put("state", "状态")
                .build();
    }

    @Override
    public List<String> getContributors() {
        return Lists.newArrayList(
                "com.restaurant.application.reservation.Reservation");
    }

    @Override
    public ReservationListBean fakeBean() {
        ReservationListBean bean = new ReservationListBean();

        bean.setReservationUid(UID.recover("A -3328769177723441452 looooong string"));
        bean.setId("A 2412249846284105110 looooong string");
        bean.setCreateTime(65432776L);
        bean.setModifyTime(91217672L);
        bean.setNumber("A 2850745592190421021 looooong string");
        bean.setShopUid("A -3412124159144356472 looooong string");
        bean.setShopName("A -4942021005897805205 looooong string");
        bean.setServiceName("A -673376192308435412 looooong string");
        bean.setPersonAmount("A -3902571933106213313 looooong string");
        bean.setDate(-1961116150L);
        bean.setTime("A -1992616520090216433 looooong string");
        bean.setCustomerId("A -51067314183598134 looooong string");
        bean.setCustomerUid("A -2654143449223627776 looooong string");
        bean.setCustomerName("A 7926835120849099777 looooong string");
        bean.setPhone("A -8179934177628049939 looooong string");
        bean.setRemarks("A 578786917960192544 looooong string");
        bean.setState("A -5418060083956237358 looooong string");
        return bean;
    }

    @Override
    public String getCreateTableStatement() {
        StringBuilder buf = new StringBuilder();

        buf.append("CREATE TABLE IF NOT EXISTS " + getConnectionName() + ".RESERVATIONLIST (\n");
        buf.append("    RECORD_ID BIGINT AUTO_INCREMENT,\n");
        buf.append("    RESERVATIONUID CHAR(128) CHARACTER SET latin1 COLLATE latin1_general_cs NOT NULL,\n");
        buf.append("    ID VARCHAR(255),\n");
        buf.append("    CREATETIME BIGINT,\n");
        buf.append("    MODIFYTIME BIGINT,\n");
        buf.append("    NUMBER VARCHAR(255),\n");
        buf.append("    SHOPUID VARCHAR(255),\n");
        buf.append("    SHOPNAME VARCHAR(255),\n");
        buf.append("    SERVICENAME VARCHAR(255),\n");
        buf.append("    PERSONAMOUNT VARCHAR(255),\n");
        buf.append("    DATE BIGINT,\n");
        buf.append("    TIME VARCHAR(255),\n");
        buf.append("    CUSTOMERID VARCHAR(255),\n");
        buf.append("    CUSTOMERUID VARCHAR(255),\n");
        buf.append("    CUSTOMERNAME VARCHAR(255),\n");
        buf.append("    PHONE VARCHAR(255),\n");
        buf.append("    REMARKS VARCHAR(255),\n");
        buf.append("    STATE VARCHAR(255),\n");
        buf.append("PRIMARY KEY (RECORD_ID)) CHARACTER SET  = utf8mb4 COLLATE = utf8mb4_bin");
        return buf.toString();
    }

    @Override
    public String getInsertDataStatement(ReservationListBean data) {
        StringBuilder buf = new StringBuilder();

        buf.append("INSERT INTO " + getConnectionName() + ".RESERVATIONLIST (\n    ");
        buf.append("    RESERVATIONUID, ID, CREATETIME, MODIFYTIME, NUMBER, SHOPUID, SHOPNAME, SERVICENAME, PERSONAMOUNT, DATE, TIME, CUSTOMERID, CUSTOMERUID, CUSTOMERNAME, PHONE, REMARKS, STATE");
        buf.append(") VALUES (");
        buf.append("    '" + cut(data.getReservationUid(), 128) + "', '" + cut(data.getId(), 255) + "', " + data.getCreateTime() + ", " + data.getModifyTime() + ", '" + cut(data.getNumber(), 255) + "', '" + cut(data.getShopUid(), 255) + "', '" + cut(data.getShopName(), 255) + "', '" + cut(data.getServiceName(), 255) + "', '" + cut(data.getPersonAmount(), 255) + "', " + data.getDate() + ", '" + cut(data.getTime(), 255) + "', '" + cut(data.getCustomerId(), 255) + "', '" + cut(data.getCustomerUid(), 255) + "', '" + cut(data.getCustomerName(), 255) + "', '" + cut(data.getPhone(), 255) + "', '" + cut(data.getRemarks(), 255) + "', '" + cut(data.getState(), 255) + "'");
        buf.append(")");
        return buf.toString();
    }

    @Override
    public String getDeleteRowsStatement(Long rowId) {
        return "DELETE FROM " + getConnectionName() + ".RESERVATIONLIST WHERE  RECORD_ID = " + rowId;
    }

    @Override
    public String getLocalUpdateStatement(ReservationListBean data) {
        StringBuilder buf = new StringBuilder();
        StringBuilder sep = new StringBuilder();

        boolean hasData = false;

        buf.append("UPDATE " + getConnectionName() + ".RESERVATIONLIST \n");
        buf.append("   SET ");
        if(data.getReservationUid() != null) {
            buf.append(sep.toString() + "\n      RESERVATIONUID = '" + cut(data.getReservationUid(), 128) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getId() != null) {
            buf.append(sep.toString() + "\n      ID = '" + cut(data.getId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCreateTime() != null) {
            buf.append(sep.toString() + "\n      CREATETIME = " + data.getCreateTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getModifyTime() != null) {
            buf.append(sep.toString() + "\n      MODIFYTIME = " + data.getModifyTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getNumber() != null) {
            buf.append(sep.toString() + "\n      NUMBER = '" + cut(data.getNumber(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopUid() != null) {
            buf.append(sep.toString() + "\n      SHOPUID = '" + cut(data.getShopUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopName() != null) {
            buf.append(sep.toString() + "\n      SHOPNAME = '" + cut(data.getShopName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getServiceName() != null) {
            buf.append(sep.toString() + "\n      SERVICENAME = '" + cut(data.getServiceName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getPersonAmount() != null) {
            buf.append(sep.toString() + "\n      PERSONAMOUNT = '" + cut(data.getPersonAmount(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getDate() != null) {
            buf.append(sep.toString() + "\n      DATE = " + data.getDate() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getTime() != null) {
            buf.append(sep.toString() + "\n      TIME = '" + cut(data.getTime(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerId() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERID = '" + cut(data.getCustomerId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerUid() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERUID = '" + cut(data.getCustomerUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerName() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERNAME = '" + cut(data.getCustomerName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getPhone() != null) {
            buf.append(sep.toString() + "\n      PHONE = '" + cut(data.getPhone(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getRemarks() != null) {
            buf.append(sep.toString() + "\n      REMARKS = '" + cut(data.getRemarks(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getState() != null) {
            buf.append(sep.toString() + "\n      STATE = '" + cut(data.getState(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(!hasData) return "";

        hasData = false;
        buf.append(" WHERE TRUE\n");
        if(data.getReservationUid() != null) {
            buf.append("    AND RESERVATIONUID = '" + data.getReservationUid() + "'\n");
            hasData = true;
        }
        if(!hasData) return "";

        return buf.toString();
    }

    @Override
    public String getUpdateByIdStatement(ReservationListBean data) {
        StringBuilder buf = new StringBuilder();
        StringBuilder sep = new StringBuilder();

        boolean hasData = false;

        buf.append("UPDATE " + getConnectionName() + ".RESERVATIONLIST \n");
        buf.append("   SET ");
        if(data.getReservationUid() != null) {
            buf.append(sep.toString() + "\n      RESERVATIONUID = '" + cut(data.getReservationUid(), 128) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getId() != null) {
            buf.append(sep.toString() + "\n      ID = '" + cut(data.getId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCreateTime() != null) {
            buf.append(sep.toString() + "\n      CREATETIME = " + data.getCreateTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getModifyTime() != null) {
            buf.append(sep.toString() + "\n      MODIFYTIME = " + data.getModifyTime() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getNumber() != null) {
            buf.append(sep.toString() + "\n      NUMBER = '" + cut(data.getNumber(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopUid() != null) {
            buf.append(sep.toString() + "\n      SHOPUID = '" + cut(data.getShopUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getShopName() != null) {
            buf.append(sep.toString() + "\n      SHOPNAME = '" + cut(data.getShopName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getServiceName() != null) {
            buf.append(sep.toString() + "\n      SERVICENAME = '" + cut(data.getServiceName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getPersonAmount() != null) {
            buf.append(sep.toString() + "\n      PERSONAMOUNT = '" + cut(data.getPersonAmount(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getDate() != null) {
            buf.append(sep.toString() + "\n      DATE = " + data.getDate() + "");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if (data.getTime() != null) {
            buf.append(sep.toString() + "\n      TIME = '" + cut(data.getTime(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerId() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERID = '" + cut(data.getCustomerId(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerUid() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERUID = '" + cut(data.getCustomerUid(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getCustomerName() != null) {
            buf.append(sep.toString() + "\n      CUSTOMERNAME = '" + cut(data.getCustomerName(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getPhone() != null) {
            buf.append(sep.toString() + "\n      PHONE = '" + cut(data.getPhone(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getRemarks() != null) {
            buf.append(sep.toString() + "\n      REMARKS = '" + cut(data.getRemarks(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(data.getState() != null) {
            buf.append(sep.toString() + "\n      STATE = '" + cut(data.getState(), 255) + "'");
            hasData = true;
            sep.setLength(0);
            sep.append(",");
        }
        if(!hasData) return "";

        hasData = false;
        buf.append(" WHERE RECORD_ID = " + data.getRecordId());
        return buf.toString();
    }

    @Override
    public ReservationListBean extractLine(ResultSet resultSet) throws Exception {
        ReservationListBean result = new ReservationListBean();

        result.setRecordId(resultSet.getLong("RECORD_ID"));
        result.setReservationUid(UID.recover(resultSet.getString("reservationUid")));
        result.setId(resultSet.getString("id"));
        result.setCreateTime(resultSet.getLong("createTime"));
        result.setModifyTime(resultSet.getLong("modifyTime"));
        result.setNumber(resultSet.getString("number"));
        result.setShopUid(resultSet.getString("shopUid"));
        result.setShopName(resultSet.getString("shopName"));
        result.setServiceName(resultSet.getString("serviceName"));
        result.setPersonAmount(resultSet.getString("personAmount"));
        result.setDate(resultSet.getLong("date"));
        result.setTime(resultSet.getString("time"));
        result.setCustomerId(resultSet.getString("customerId"));
        result.setCustomerUid(resultSet.getString("customerUid"));
        result.setCustomerName(resultSet.getString("customerName"));
        result.setPhone(resultSet.getString("phone"));
        result.setRemarks(resultSet.getString("remarks"));
        result.setState(resultSet.getString("state"));
        return result;
    }

    @Override
    public String getWherePart(ReservationListCriteria criteria, SortSpec sort) {
        StringBuilder buf = new StringBuilder(" TRUE ");

        criteria.setIdLike(searchString(criteria.getIdLike()));
        criteria.setNumberLike(searchString(criteria.getNumberLike()));
        criteria.setShopUidLike(searchString(criteria.getShopUidLike()));
        criteria.setShopNameLike(searchString(criteria.getShopNameLike()));
        criteria.setServiceNameLike(searchString(criteria.getServiceNameLike()));
        criteria.setPersonAmountLike(searchString(criteria.getPersonAmountLike()));
        criteria.setTimeLike(searchString(criteria.getTimeLike()));
        criteria.setCustomerIdLike(searchString(criteria.getCustomerIdLike()));
        criteria.setCustomerUidLike(searchString(criteria.getCustomerUidLike()));
        criteria.setCustomerNameLike(searchString(criteria.getCustomerNameLike()));
        criteria.setPhoneLike(searchString(criteria.getPhoneLike()));
        criteria.setRemarksLike(searchString(criteria.getRemarksLike()));
        criteria.setStateLike(searchString(criteria.getStateLike()));

        if(criteria.getRecordId() != null) {
            buf.append("    AND RECORD_ID = " + criteria.getRecordId());
        }
        if(criteria.getReservationUidEquals() != null) {
            buf.append("    AND RESERVATIONUID = '" + criteria.getReservationUidEquals() + "'");
        }
        if(criteria.getReservationUidNotEquals() != null) {
            buf.append("    AND RESERVATIONUID != '" + criteria.getReservationUidNotEquals() + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getIdEquals())) {
            buf.append("    AND ID = '" + cut(criteria.getIdEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getIdNotEquals())) {
            buf.append("    AND ID != '" + cut(criteria.getIdNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getIdLike())) {
            buf.append("    AND ID LIKE '" + cut(criteria.getIdLike()) + "'");
        }
        if(criteria.getCreateTimeUpper() != null) {
            buf.append("    AND CREATETIME <= " + criteria.getCreateTimeUpper());
        }
        if(criteria.getCreateTimeLower() != null) {
            buf.append("    AND CREATETIME >= " + criteria.getCreateTimeLower());
        }
        if(criteria.getCreateTimeEquals() != null) {
            buf.append("    AND CREATETIME = '" + criteria.getCreateTimeEquals() + "'");
        }
        if(criteria.getCreateTimeNotEquals() != null) {
            buf.append("    AND CREATETIME != '" + criteria.getCreateTimeNotEquals() + "'");
        }
        if(criteria.getModifyTimeUpper() != null) {
            buf.append("    AND MODIFYTIME <= " + criteria.getModifyTimeUpper());
        }
        if(criteria.getModifyTimeLower() != null) {
            buf.append("    AND MODIFYTIME >= " + criteria.getModifyTimeLower());
        }
        if(criteria.getModifyTimeEquals() != null) {
            buf.append("    AND MODIFYTIME = '" + criteria.getModifyTimeEquals() + "'");
        }
        if(criteria.getModifyTimeNotEquals() != null) {
            buf.append("    AND MODIFYTIME != '" + criteria.getModifyTimeNotEquals() + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNumberEquals())) {
            buf.append("    AND NUMBER = '" + cut(criteria.getNumberEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNumberNotEquals())) {
            buf.append("    AND NUMBER != '" + cut(criteria.getNumberNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getNumberLike())) {
            buf.append("    AND NUMBER LIKE '" + cut(criteria.getNumberLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopUidEquals())) {
            buf.append("    AND SHOPUID = '" + cut(criteria.getShopUidEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopUidNotEquals())) {
            buf.append("    AND SHOPUID != '" + cut(criteria.getShopUidNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopUidLike())) {
            buf.append("    AND SHOPUID LIKE '" + cut(criteria.getShopUidLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopNameEquals())) {
            buf.append("    AND SHOPNAME = '" + cut(criteria.getShopNameEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopNameNotEquals())) {
            buf.append("    AND SHOPNAME != '" + cut(criteria.getShopNameNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getShopNameLike())) {
            buf.append("    AND SHOPNAME LIKE '" + cut(criteria.getShopNameLike()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getServiceNameEquals())) {
            buf.append("    AND SERVICENAME = '" + cut(criteria.getServiceNameEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getServiceNameNotEquals())) {
            buf.append("    AND SERVICENAME != '" + cut(criteria.getServiceNameNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getServiceNameLike())) {
            buf.append("    AND SERVICENAME LIKE '" + cut(criteria.getServiceNameLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPersonAmountEquals())) {
            buf.append("    AND PERSONAMOUNT = '" + cut(criteria.getPersonAmountEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPersonAmountNotEquals())) {
            buf.append("    AND PERSONAMOUNT != '" + cut(criteria.getPersonAmountNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPersonAmountLike())) {
            buf.append("    AND PERSONAMOUNT LIKE '" + cut(criteria.getPersonAmountLike()) + "'");
        }
        if (criteria.getDateUpper() != null) {
            buf.append("    AND DATE <= " + criteria.getDateUpper());
        }
        if (criteria.getDateLower() != null) {
            buf.append("    AND DATE >= " + criteria.getDateLower());
        }
        if (criteria.getDateEquals() != null) {
            buf.append("    AND DATE = '" + criteria.getDateEquals() + "'");
        }
        if (criteria.getDateNotEquals() != null) {
            buf.append("    AND DATE != '" + criteria.getDateNotEquals() + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getTimeEquals())) {
            buf.append("    AND TIME = '" + cut(criteria.getTimeEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getTimeNotEquals())) {
            buf.append("    AND TIME != '" + cut(criteria.getTimeNotEquals()) + "'");
        }
        if (!Strings.isNullOrEmpty(criteria.getTimeLike())) {
            buf.append("    AND TIME LIKE '" + cut(criteria.getTimeLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerIdEquals())) {
            buf.append("    AND CUSTOMERID = '" + cut(criteria.getCustomerIdEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerIdNotEquals())) {
            buf.append("    AND CUSTOMERID != '" + cut(criteria.getCustomerIdNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerIdLike())) {
            buf.append("    AND CUSTOMERID LIKE '" + cut(criteria.getCustomerIdLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerUidEquals())) {
            buf.append("    AND CUSTOMERUID = '" + cut(criteria.getCustomerUidEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerUidNotEquals())) {
            buf.append("    AND CUSTOMERUID != '" + cut(criteria.getCustomerUidNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerUidLike())) {
            buf.append("    AND CUSTOMERUID LIKE '" + cut(criteria.getCustomerUidLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerNameEquals())) {
            buf.append("    AND CUSTOMERNAME = '" + cut(criteria.getCustomerNameEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerNameNotEquals())) {
            buf.append("    AND CUSTOMERNAME != '" + cut(criteria.getCustomerNameNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getCustomerNameLike())) {
            buf.append("    AND CUSTOMERNAME LIKE '" + cut(criteria.getCustomerNameLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPhoneEquals())) {
            buf.append("    AND PHONE = '" + cut(criteria.getPhoneEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPhoneNotEquals())) {
            buf.append("    AND PHONE != '" + cut(criteria.getPhoneNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getPhoneLike())) {
            buf.append("    AND PHONE LIKE '" + cut(criteria.getPhoneLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRemarksEquals())) {
            buf.append("    AND REMARKS = '" + cut(criteria.getRemarksEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRemarksNotEquals())) {
            buf.append("    AND REMARKS != '" + cut(criteria.getRemarksNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getRemarksLike())) {
            buf.append("    AND REMARKS LIKE '" + cut(criteria.getRemarksLike()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getStateEquals())) {
            buf.append("    AND STATE = '" + cut(criteria.getStateEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getStateNotEquals())) {
            buf.append("    AND STATE != '" + cut(criteria.getStateNotEquals()) + "'");
        }
        if(!Strings.isNullOrEmpty(criteria.getStateLike())) {
            buf.append("    AND STATE LIKE '" + cut(criteria.getStateLike()) + "'");
        }
        if(sort != null && sort.getColumns().size() > 0) {
            buf.append(" ORDER BY ");
            sort.getColumns().forEach(c->buf.append(c.getColumnName().toUpperCase())
                .append(" ").append((c.getAscending() != null && c.getAscending()) ? "ASC" : "DESC")
                .append(", "));
            buf.append("RECORD_ID ASC");
        }
        return buf.toString();
    }

    @Override
    public <T extends Unit > String getUpdateStatement(T source) {
        ReservationListBean data = null;

        if(source instanceof com.restaurant.application.indexes.reservationlist.mysql.ReservationListFromreservationUidIF) {
            data = new ReservationListBean();
             ((com.restaurant.application.indexes.reservationlist.mysql.ReservationListFromreservationUidIF)source).getReservationUidDataForReservationList(data);
        }

        return data == null ? null: getLocalUpdateStatement(data);
    }
}
